package com.ruoyi.chat.controller;

import com.ruoyi.chat.dto.ChatDtoReq;
import com.ruoyi.chat.entity.ChatTypeEnum;
import com.ruoyi.chat.service.BookService;
import com.ruoyi.chat.service.ChatMovieService;
import com.ruoyi.chat.service.GameService;
import com.ruoyi.common.core.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * 聊天管理
 */
@RestController
@RequestMapping("/chat")
@Slf4j
public class ChatController {

    @Resource
    private ChatMovieService chatMovieService;

    @Resource
    private GameService gameService;

    @Resource
    private BookService bookService;;

    @PostMapping("/send")
    public AjaxResult sendMessage(@RequestBody ChatDtoReq req){
        log.info("入参:{}",req.toString());
        if(ChatTypeEnum.MOVIE.getCode().equals(req.getCategory())){
            startPage();
            return AjaxResult.success(chatMovieService.chat(req));
        }
        if(ChatTypeEnum.GAME.getCode().equals(req.getCategory())){
            return AjaxResult.success(gameService.getGames(req));
        }
        if(ChatTypeEnum.BOOK.getCode().equals(req.getCategory())){
            return AjaxResult.success(bookService.getBooks(req));
        }
        return AjaxResult.success(null);
    }
}
